import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
import java.util.Random;

import javax.swing.*;


public class Nucleo extends JPanel implements Runnable{

	private LinkedList<Actor> actores=new LinkedList<Actor>();
	
	
	public Nucleo(){
		setSize(Ventana.ancho,Ventana.alto);
//		this.addKeyListener(new keyL());
	}
	
	void press(KeyEvent e){
		if (e.getKeyCode()==KeyEvent.VK_UP){
			actores.get(0).setVSpeed(-1);
		}
		if (e.getKeyCode()==KeyEvent.VK_DOWN){
			actores.get(0).setVSpeed(1);
		}
		if (e.getKeyCode()==KeyEvent.VK_LEFT){
			actores.get(0).setHSpeed(-1);
		}
		if (e.getKeyCode()==KeyEvent.VK_RIGHT){
			actores.get(0).setHSpeed(1);
		}
		this.repaint();
	}
	void move(){
		for (int i=0;i<actores.size();i++){
			actores.get(i).move();
		}
	}
	void release(KeyEvent e){
		if (e.getKeyCode()==KeyEvent.VK_UP){
			actores.get(0).setVSpeed(0);
		}
		if (e.getKeyCode()==KeyEvent.VK_DOWN){
			actores.get(0).setVSpeed(0);
		}
		if (e.getKeyCode()==KeyEvent.VK_LEFT){
			actores.get(0).setHSpeed(0);
		}
		if (e.getKeyCode()==KeyEvent.VK_RIGHT){
			actores.get(0).setHSpeed(0);
		}
	
	}
	public void paint(Graphics g){
//		super.paint(g);
		Graphics2D g2=(Graphics2D)g;
		g2.setColor(Color.WHITE);
		g2.fillRect(0, 0, Ventana.ancho, Ventana.alto);
		g2.setColor(Color.BLUE);
		for (int i=0;i<actores.size();i++){
			actores.get(i).paint(g);
		}
	}
	
	public void add(Actor actor){
		actores.add(actor);
	}

	@Override
	public void run() {
		
		try {
			while(true){
				move();
				this.repaint();
				Thread.sleep(5);
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
